package com.hxzy.util;


import com.hxzy.vo.AdminLoginVO;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * 获取后台登录用户信息
 */
public class AdminInfoUtil {

    /**
     * 得到后台用户信息
     * @return
     */
    public static AdminLoginVO getAdmin(){
         UsernamePasswordAuthenticationToken authenticationToken= (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();

         AdminLoginVO adminLoginVO= (AdminLoginVO) authenticationToken.getPrincipal();
        return adminLoginVO;
    }


    /**
     * 得到当前的用户ID
     * @return
     */
    public static Long getUserId(){
        return getAdmin().getSysUser().getUserId();
    }


}
